package com.study.h190808viewpagerstudy;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

/**
 * 项目名: H190808ViewPagerStudy
 * 包 名:  com.study.h190808viewpagerstudy
 * 文件名: ViewPagerFragment
 * 创建者: hw2019
 * 时 间:  2019-08-08 14:28
 * 描 述:  TODO
 */

public class ViewPagerFragment extends Fragment {

    private String mTitle;
    private View rootView;
    public static final String BUNDLE_TITLE = "title";

    public static ViewPagerFragment newInstance(String title){
        Bundle bundle = new Bundle();
        bundle.putString(BUNDLE_TITLE, title);

        ViewPagerFragment fragment = new ViewPagerFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        Bundle bundle = getArguments();
        if (bundle != null){
            mTitle = bundle.getString(BUNDLE_TITLE);
        }

        if ("商品".equals(mTitle)){
            //Note：创建商品界面（第一个界面）
            rootView = inflater.inflate(R.layout.fragment_goods_layout, container, false);

        } else if ("详情".equals(mTitle)) {
            //Note：创建详情界面（第二个界面）
            rootView = inflater.inflate(R.layout.fragment_detail_layout, container, false);

        } else {
            //Note：创建评论界面（第三个界面）
            rootView = inflater.inflate(R.layout.fragment_comment_layout, container, false);
        }

        return rootView;
    }
}
